A=2;
x=-pi:0.1:pi;

fx1=A/2;
fxdd1=fx1
subplot(2,3,1),plot(x,fxdd1,'k'),xlabel('(a) 前1次谐波迭代');

hold on;
fx2=A/2+2*A/pi*(sin(1*pi*x/2)/1);
fxdd2=fx1+fx2;
subplot(2,3,2),plot(x,fxdd2,'k'),xlabel('(b) 前2次谐波迭代');

hold on;
fx3=A/2+2*A/pi*(sin(1*pi*x/2)/1+sin(3*pi*x/2)/3);
fxdd3=fx1+fx2+fx3;
subplot(2,3,3),plot(x,fxdd3,'k'),xlabel('(c) 前3次谐波迭代');

hold on;
fx4=A/2+2*A/pi*(sin(1*pi*x/2)/1+sin(3*pi*x/2)/3+sin(5*pi*x/2)/5);
fxdd4=fx1+fx2+fx3+fx4;
subplot(2,3,4),plot(x,fxdd4,'k'),xlabel('(d) 前4次谐波迭代');

hold on;
fx5=A/2+2*A/pi*(sin(1*pi*x/2)/1+sin(3*pi*x/2)/3+sin(5*pi*x/2)/5+sin(5*pi*x/2)/7);
fxdd5=fx1+fx2+fx3+fx4+fx5;
subplot(2,3,5),plot(x,fxdd5,'k'),xlabel('(e) 前5次谐波迭代');

hold on;
syms n;
k=symsum(2*A/pi*sin((2*n+1)*pi*x/2)/(2*n+1),0,39);
fxdd80=A/2+subs(k);
subplot(2,3,6),plot(x,fxdd80,'k'),xlabel('(f) 前40次谐波迭代'),box off;